package com.hjm.project.agentInfo.agentPolicy.controller;

import java.util.List;

import com.hjm.project.agentInfo.agentPolicy.domain.AgentPolicy;
import com.hjm.project.agentInfo.agentPolicy.service.IAgentPolicyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 代理结算底价Controller
 * 
 * @author maker-platform
 * @date 2024-03-21
 */
@Controller
@RequestMapping("/agentInfo/agentPolicy")
public class AgentPolicyController extends BaseController {
    private String prefix = "agentInfo/agentPolicy";

    @Resource
    private IAgentPolicyService agentPolicyService;

    @RequiresPermissions("agentInfo:agentPolicy:view")
    @GetMapping()
    public String agentPolicy() {
        return prefix + "/agentPolicy";
    }

    /**
     * 查询代理结算底价列表
     */
    @RequiresPermissions("agentInfo:agentPolicy:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentPolicy agentPolicy) {
        startPage();
        List<AgentPolicy> list = agentPolicyService.selectAgentPolicyList(agentPolicy);
        return getDataTable(list);
    }

    /**
     * 导出代理结算底价列表
     */
    @RequiresPermissions("agentInfo:agentPolicy:export")
    @Log(title = "代理结算底价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentPolicy agentPolicy) {
        List<AgentPolicy> list = agentPolicyService.selectAgentPolicyList(agentPolicy);
        ExcelUtil<AgentPolicy> util = new ExcelUtil<AgentPolicy>(AgentPolicy.class);
        return util.exportExcel(list, "agentPolicy");
    }

    /**
     * 新增代理结算底价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理结算底价
     */
    @RequiresPermissions("agentInfo:agentPolicy:add")
    @Log(title = "代理结算底价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentPolicy agentPolicy) {
        return toAjax(agentPolicyService.insertAgentPolicy(agentPolicy));
    }

    /**
     * 修改代理结算底价
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        AgentPolicy agentPolicy = agentPolicyService.selectAgentPolicyById(id);
        mmap.put("agentPolicy", agentPolicy);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理结算底价
     */
    @RequiresPermissions("agentInfo:agentPolicy:edit")
    @Log(title = "代理结算底价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentPolicy agentPolicy) {
        return toAjax(agentPolicyService.updateAgentPolicy(agentPolicy));
    }

    /**
     * 删除代理结算底价
     */
    @RequiresPermissions("agentInfo:agentPolicy:remove")
    @Log(title = "代理结算底价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentPolicyService.deleteAgentPolicyByIds(ids));
    }
}
